import httplib, sys
import httpproxylib
from BioModelsWebServicesService_services import *

class BioModels(object):
    
    def __init__(self, http_proxy=''):

        loc = BioModelsWebServicesServiceLocator()
        self.binding = loc.getBioModelsWebServices(transport=httpproxylib.HTTPProxyConnection, \
            transdict={'proxy':http_proxy})

    def __createRequest(self, bio_id=None):
        method = self.__caller
        request = eval(method + 'Request',)()

        if bio_id:
            attrs = dir(request)
            for value in ['__doc__', '__init__', '__module__', 'typecode']:
                attrs.remove(value)
            if len(attrs) >1:
                raise "Wasn't expecting more than one value"     
            setattr(request, attrs[0], bio_id)    

        response = getattr(self.binding, method)(request)
        return getattr(response, '_' + method + 'Return')
        
    def __getattribute__(self, name):
        if name[:1] != '_':
            self.__caller = name
        return object.__getattribute__(self, name)  
    
    def helloBioModels(self):
        return self.__createRequest()
        
    def getAllCuratedModelsId(self):
        '''Retrieves all curated models' id in a string array.'''
        return self.__createRequest()
    
    def getAllModelsId(self):
        '''Retrieves models' id of both curated and non-curated models.'''
        return self.__createRequest()
    
    
    def getAllNonCuratedModelsId(self):
        '''Retrieves all non-curated models' id in a string array.'''
        return self.__createRequest()

    def getModelNameById(bio_id):
        '''Retrieves the model name in string.'''
        return self.__createRequest()

    def getModelById(self, bio_id):
        '''Deprecated. Replaced by getModelSBMLById(String id)'''
        return self.__createRequest(bio_id)

    def getModelSBMLById(self, bio_id):
        '''Retrieves the SBML model in string.'''
        return self.__createRequest(bio_id)
        
    def getSimpleModelById(self, bio_id):
        '''Retrieves the model by model ID.'''
        return self.__createRequest(bio_id)
        
    def getModelsIdByChEBI(self,bio_id):
        '''Retrieves all models' id which are relevant to the given ChEBI text'''
        return self.__createRequest(bio_id)
                
    def getModelsIdByChEBIId(self,bio_id):
        '''Retrieves all models' id which are related to the given ChEBI item'''
        return self.__createRequest(bio_id)
        
    def getModelsIdByGO(self,bio_id):
        '''Retrieves the models' ID which are relevant with the given Gene Ontology text'''
        return self.__createRequest(bio_id)
	
    def getModelsIdByGOId(bio_id):
        '''Retrieves the models' ID which are related to given Gene Ontology item'''
        return self.__createRequest(bio_id)

    def getModelsIdByName(self,bio_id):
        '''Retrieves all models' id with same string in names'''
        return self.__createRequest(bio_id)
        
    def getModelsIdByPerson(self,bio_id):
        '''Retrieves all models' id which has certain person as author or modeller'''
        return self.__createRequest(bio_id)
        
    def getModelsIdByPublication(self,bio_id):
        '''Retrieves all models' id which has same publication id or text'''
        return self.__createRequest(bio_id)
            
    def getModelsIdByTaxonomy(self,bio_id):
        '''Retrieves the models' ID which are relevant with given Taxonomy text'''
        return self.__createRequest(bio_id)
        
    def getModelsIdByTaxonomyId(self,bio_id):
        '''Retrieves the models' ID which are related to given Taxonomy item'''
        self.__createRequest(bio_id)
        
    def getModelsIdByUniprot(self,bio_id):
        '''Retrieves the models' ID which are revelant to the given UniProt text'''
        return self.__createRequest(bio_id)
        
    def getModelsIdByUniprotId(self,bio_id):
        '''Retrieves all models' id which are related to the given UniProt item'''
        return self.__createRequest(bio_id)

    def getModelsIdByUniprotIds(self, bio_id):
        '''Retrieves the models' ID which are related to given UniProt Ids'''
        return self.__createRequest(bio_id)
        
    def getSimpleModelsByChEBIIds(self, bio_id):
        '''Retrieves the models' ID which are annotated with a couple of specified ChEBI Ids'''
        return self.__createRequest(bio_id)
                   
    def getSimpleModelsByUniprotIds(self, bio_id):
        '''Retrieves the models' ID which are annotated with a couple of specified UniProt Ids'''
        return self.__createRequest(bio_id)        
        
        
    def getSimpleModelsRelatedWithChEBI(self):
        '''Retrieves all models' which are annotated with ChEBI terms'''
        return self.__createRequest()        
        
    def getSimpleModelsByReactomeIds(self, bio_id):
        return self.__createRequest(bio_id)        
        
         
 

if __name__ == '__main__':
    b= BioModels('proxy.nbn.sun.ac.za:3128')
    print b.helloBioModels()
#    print b.getAllModelsId()
#    print b.getModelSBMLById('MODEL9070467164')
#    print b.getSimpleModelsByReactomeIds(['REACT_152'])
    print b.getModelsIdByPerson('gillespie')
